package ${package.Entity};

<#list table.importPackages as pkg>
import ${pkg};
</#list>
<#if swagger>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
</#if>
<#if entityLombokModel>
import lombok.Getter;
import lombok.Setter;
	<#if chainModel>
import lombok.experimental.Accessors;
	</#if>
</#if>
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * ${table.comment!}
 * @author ${author}
 * @since ${date}
 */
<#if entityLombokModel>
@Getter
@Setter
	<#if chainModel>
@Accessors(chain = true)
	</#if>
</#if>
<#if table.convert>
@TableName("${schemaName}${table.name}")
</#if>
<#if swagger>
@ApiModel(value = "${entity}对象", description = "${table.comment!}")
</#if>
<#if superEntityClass??>
public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
<#elseif activeRecord>
public class ${entity} extends Model<${entity}> {
<#elseif entitySerialVersionUID>
public class ${entity} implements Serializable {
<#else>
public class ${entity} {
</#if>
<#if entitySerialVersionUID>

	private static final long serialVersionUID = 1L;
</#if>
<#-- ----------  BEGIN 字段循环遍历  ---------->
<#list table.fields as field>
	<#-- 外部注入的数据表元数据 -->
	<#assign dbColumn = columnsMap['${field.propertyName}']>
	<#-- 后台字段的意思就是没有业务含义，不需要用户填入的字段，这类字段不展示swagger注解的required和allowableValues等属性（也不会触发注解内容换行）。-->
	<#assign isBackgroundField = field.comment?contains('自动赋值') || field.comment?contains('后台赋值')>
	<#-- 此标识的含义：数据库字段为not null，并且不是自增也没有默认值，也不是后台统一赋值，而是需要由前端传入。-->
	<#assign notAllowNull = !dbColumn.isNullable() && !dbColumn.isAutoincr() && GeneralUtil.isBlank(dbColumn.getDefaultValue()) && !isBackgroundField>
	<#assign isString = dbColumn.getJavaType() == 'String'>
	<#if field.keyFlag>
		<#assign keyPropertyName="${field.propertyName}"/>
	</#if>

	<#if field.comment!?length gt 0>
	/** ${field.comment}<#if !field.comment?matches('.+' + constants.UnifiedConstants.REGEX_NOT_WORD_CHAR)> </#if>*/
		<#if swagger>
			<#-- dataType属性是个废的，用dataType = "string(${dbColumn.getSize()})"无法在网页上显示任何东西。-->
			<#-- 当字段需要声明其它属性并且字段注释超过一定长度时，需要换行。-->
	@ApiModelProperty(value = "${field.comment}<#if field.propertyType == 'LocalDateTime' && !field.comment?contains("yyyy-MM-dd HH:mm:ss")>（yyyy-MM-dd HH:mm:ss）</#if>",<#if !isBackgroundField><#if (notAllowNull || isString) && field.comment?length gt 15>${"\n\t\t\t"}<#else> </#if><#if notAllowNull>required = true, </#if><#if isString>allowableValues = "range[,${dbColumn.getSize()?c}]", </#if><#else> </#if>position = ${dbColumn.getOrdinal()})
		</#if>
	</#if>
	<#if field.keyFlag>
		<#-- 主键 -->
		<#if field.keyIdentityFlag>
	@TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
		<#elseif idType??>
	@TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
		<#elseif field.convert>
	@TableId("${field.annotationColumnName}")
		</#if>
		<#-- 普通字段 -->
	<#elseif field.fill??>
	<#-- -----   存在字段填充设置   ----->
		<#if field.convert>
	@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
		<#else>
	@TableField(fill = FieldFill.${field.fill})
		</#if>
	<#elseif field.convert>
	@TableField("${field.annotationColumnName}")
	</#if>
	<#-- 乐观锁注解 -->
	<#if field.versionField>
	@Version
	</#if>
	<#-- 逻辑删除注解 -->
	<#if field.logicDeleteField>
	@TableLogic
	</#if>
	<#if notAllowNull>
		<#if isString>
	@NotBlank
		<#else>
	@NotNull
		</#if>
	</#if>
	<#if field.propertyType == 'LocalDateTime'>
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	</#if>
<#--	private ${field.propertyType} ${field.propertyName};-->
	private ${MicroUtil.subBehind(dbColumn.getJavaType(), '.')} ${field.propertyName};
</#list>
<#------------  END 字段循环遍历  ---------->

<#if !entityLombokModel>
	<#list table.fields as field>
		<#if field.propertyType == "boolean">
			<#assign getprefix="is"/>
		<#else>
			<#assign getprefix="get"/>
		</#if>
	public ${field.propertyType} ${getprefix}${field.capitalName}() {
		return ${field.propertyName};
	}

	<#if chainModel>
	public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
	<#else>
	public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
	</#if>
		this.${field.propertyName} = ${field.propertyName};
		<#if chainModel>
		return this;
		</#if>
	}
	</#list>
</#if>
<#if entityColumnConstant>
	<#list table.fields as field>
	public static final String ${field.name?upper_case} = "${field.name}";

	</#list>
</#if>
<#if activeRecord>
	@Override
	public Serializable pkVal() {
	<#if keyPropertyName??>
		return this.${keyPropertyName};
	<#else>
		return null;
	</#if>
	}

</#if>
<#if !entityLombokModel>
	@Override
	public String toString() {
		return "${entity}{" +
	<#list table.fields as field>
		<#if field_index==0>
			"${field.propertyName}=" + ${field.propertyName} +
		<#else>
			", ${field.propertyName}=" + ${field.propertyName} +
		</#if>
	</#list>
		"}";
	}
</#if>
<#--已经生成好的常量定义代码片段-->
<#list enumFieldConstants as item>

${item}
</#list>
}